package com.hanlin.topic;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 描述：topic订阅模式消费者
 * @author:hl.yuan
 * @date:2021-03-15
 */
@Component
public class TopicCustomer {


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            key = {"user.*","hlyuan.#"},
            exchange = @Exchange(name = "hlyuan_topic", type = "topic")
    ))
    public void receiver1(String message) {
        System.out.println("topic模式消费者1：" + message);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            key = {"user.*"},
            exchange = @Exchange(name = "hlyuan_topic", type = "topic")
    ))
    public void receiver2(String message) {
        System.out.println("topic模式消费者2：" + message);
    }
}
